package com.course02.order_backend.mapper.Ost;

import com.course02.order_backend.entity.Ost.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    // 统计用户名存在数量
    @Select("SELECT COUNT(*) FROM tb_user WHERE username = #{username}")
    int countByUsername(String username);

    // 统计手机号存在数量
    @Select("SELECT COUNT(*) FROM tb_user WHERE phone = #{phone}")
    int countByPhone(String phone);

    // 插入用户（字段与数据库严格对应）
    @Insert("INSERT INTO tb_user(" +
            "username, password, real_name, gender, phone, email, avatar, is_enabled, create_time" +
            ") VALUES(" +
            "#{username}, #{password}, #{realName}, #{gender}, #{phone}, #{email}, #{avatar}, #{isEnabled}, NOW()" +
            ")")
    int insert(User user);
}